package com.weixin.engine.daily.sftp;

import com.jcraft.jsch.SftpException;
import com.weixin.common.exception.CommonException;
import com.weixin.common.sftp.SftpTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author wangchunhui
 * @date 2022/11/1 17:05
 */
@Component
@Slf4j
public class FileHandle {

    @Resource
    private SftpTemplate sftpTemplate;

    public void checkFile(String okUrl) {
        try {
            if (!sftpTemplate.exists(okUrl)) {
                throw new CommonException("ok文件不存在！");
            }
        } catch (SftpException e) {
            log.info("校验OK文件时失败，", e);
            throw new CommonException("ok文件不存在！");
        }
    }
}
